package commonwebgroup.commonwebartifact.CommandHandle;

import commonwebgroup.commonwebartifact.util.CommandUtil;
import commonwebgroup.commonwebartifact.util.StringUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Objects;

public class CommandNotPlayerHandle {

    public static boolean Execute(CommandSender sender, Command command, String label, String[] args) {
        if (Objects.isNull(args)) {
            return false;
        }
        if (args[0].equalsIgnoreCase("kook")) return kookCommandExecute(sender, args);
        sender.sendMessage("无法找到匹配指令");
        return false;
    }


    private static boolean kookCommandExecute(CommandSender sender, String[] args) {
        String result = "0";
        sender = CommandUtil.validCommandSender(sender);

        // 命令个数校验
        if (!CommandUtil.checkArgs(args, 2, null)) {
            CommandUtil.setErrorMsg(sender, "参数格式错误！");
            return false;
        }
        String command = args[1];

        // 是否为 null
        if (StringUtil.isEmpty(command)) {
            CommandUtil.setErrorMsg(sender, "参数格式错误！");
            return false;
        }
        //在线检测
        if (command.equalsIgnoreCase("checkonline")) {
            Player player = Bukkit.getPlayer(args[1]);
            if (player != null && player.isOnline()) result = "1";
        }
        //uuid获取
        else if (command.equalsIgnoreCase("getuuid")) {
            Player player = Bukkit.getPlayer(args[1]);
            if (player != null) result = player.getUniqueId().toString();
        }
        sender.sendMessage(result);
        return false;
    }


}
